package com.sdtele.tta.operation;


import java.sql.Timestamp;
import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.Task;
import com.sdtele.tta.models.User;


public class OperationSetTaskTags extends Operation {

	@Override
	public JsonResponse handle(JsonRequest jsonRequest) {
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		long taskId = jsonRequest.getJsonObject().get("taskId").getAsLong();
		String tags =jsonRequest.getJsonObject().get("tags").getAsString();
		Task task = Dac.getInstance().getTaskbyTaskid(taskId);

		if (curUser!=null) {
			if(curUser.getId()==task.getOwnerId())
			{
		         task.setTags(tags);
		         Timestamp updateTime = new Timestamp(System.currentTimeMillis());
		         task.setUpdateTime(updateTime);
					
				if (Dac.getInstance().chgTask(task)) {
					jres.setStatus(0);
					jres.setMessage("修改任务成功");
					jres.setEntity(task);
				} else {
					jres.setStatus(1);
					jres.setMessage("修改任务失败");
				}
			} else {
				jres.setStatus(1);
				jres.setMessage("您没有权限修改此任务");
			}
		} else {
			jres.setStatus(1);
			jres.setMessage("用户未登录");
		}
		return jres;
	}

}
